package com.youmans.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youmans.commonutils.R;
import com.youmans.eduservice.entity.EduCourse;
import com.youmans.eduservice.entity.EduTeacher;
import com.youmans.eduservice.service.EduCourseService;
import com.youmans.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherFront")
public class TeacherFrontController {
    @Autowired
    private EduTeacherService teacherService ;

    @Autowired
    private EduCourseService eduCourseService ;

    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page, @PathVariable long limit){
        Page<EduTeacher> teacherPage = new Page<>(page,limit) ;
        Map<String,Object> map = teacherService.getTeacherFrontList(teacherPage) ;
        return R.ok().data(map);
    }

    @GetMapping("getTeacherFrontInfo/{id}")
    public R getTeacherFrontInfo(@PathVariable String id){
        EduTeacher teacher = teacherService.getById(id);
        List<EduCourse> courseList =  eduCourseService.getListByTeacherId(id);
        return R.ok().data("teacher",teacher).data("courseList",courseList) ;
    }
}
